package com.jues.huichain.login.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.NetworkUtils;
import com.jakewharton.rxbinding2.view.RxView;
import com.jues.huichain.R;
import com.jues.huichain.login.entity.BootPageEntity;
import com.jues.huichain.login.entity.GlobalConfigEntity;
import com.jues.huichain.login.model.EntranceModel;
import com.lm.sjy.alertview.AlertView;

import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.component_base.helper.ImageLoaderHelper;
import health.lm.com.data.App;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.network.exception.ApiException;
import health.lm.com.router.ARouterConstant;

/**
 * 欢迎页
 */

public class WelcomeActivity extends XActivity {

    ImageView mIvAd;
    TextView mTvSkip;
    private CountDownTimer countDownTimer = new CountDownTimer(4000, 1000) {
        @SuppressLint("SetTextI18n")
        @Override
        public void onTick(long millisUntilFinished) {
            mTvSkip.setText("跳过(" + millisUntilFinished / 1000 + "s)");
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void onFinish() {
            mTvSkip.setText("跳过(" + 0 + "s)");
            gotoActivity(ARouterConstant.MainActivity, true);
        }
    };

    @SuppressLint("CheckResult")
    protected void initWidget() {
        //String bootImg = App.model.getBoot_img().equals("") ? "http://api.dujin.org/bing/1920.php" : App.model.getBoot_img();
        ImageLoaderHelper.getInstance().load(context, R.mipmap.welcome_launch, mIvAd);
        RxView.clicks(mTvSkip).subscribe(o -> {
            countDownTimer.cancel();
            gotoActivity(ARouterConstant.MainActivity, true);
        });
        countDownTimer.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (countDownTimer != null) countDownTimer.cancel();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mIvAd = findViewById(R.id.iv_ad);
        mTvSkip = findViewById(R.id.tv_skip);

        initWidget();
    }
}
